<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Get information about a table's columns: GNOME Data Access 5 manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GNOME Data Access 5 manual">
<link rel="up" href="howto.html" title="HOWTO for common tasks">
<link rel="prev" href="ch12s08.html" title="Execute a DDL command">
<link rel="next" href="howto-meta2.html" title="Update the meta data about a table">
<meta name="generator" content="GTK-Doc V1.32 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="howto.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="ch12s08.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="howto-meta2.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="howto-meta1"></a>Get information about a table's columns</h2></div></div></div>
<p>
      <span class="application">Libgda</span> supports reporting meta data about a database (for which there is an opened connection). The
      meta data are stored in a database (usually an in-memory database) which structure is close to the 
      information schema SQL standard (ISO/IEC 9075), and adapted (form information, this database is managed by a
      <a class="link" href="GdaMetaStore.html" title="GdaMetaStore">GdaMetaStore</a> object). As databases don't notify the changes made to
      their objects, it is necessary to update (or synchronize) the meta data if the database's schema has been
      changed, or if the meta data has not yet been extracted: call
      <a class="link" href="GdaConnection.html#gda-connection-update-meta-store" title="gda_connection_update_meta_store ()">gda_connection_update_meta_store()</a> for this purpose.
    </p>
<p>
      One then needs to find the data requested among the (rather large) quantity of meta data available, there are
      two possibilities:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>Knowing the information schema's structure (tables and views) used, 
	    run some SELECT commands on the 
	    <a class="link" href="GdaMetaStore.html" title="GdaMetaStore">GdaMetaStore</a> object's internal connection: this solution is the most
	    powerful but requires some knowledge of the information schema's structure, and the data
	    is not easy to use.</p></li>
<li class="listitem"><p>Use a <a class="link" href="GdaMetaStruct.html" title="GdaMetaStruct">GdaMetaStruct</a> object which 
	    <span class="emphasis"><em>exports</em></span> the meta data as a dynamic tree of pre-defined data structures, 
	    easy to use.</p></li>
</ul></div>
<p>
    </p>
<p>
      The following code shows how to list all the colums of the "customers" table of a connection (the connection
      is assumed to already be opened):
      </p>
<pre class="programlisting">
GdaMetaStruct *mstruct;
GdaMetaDbObject *dbo;
GValue *table_name;
if (!gda_connection_update_meta_store (cnc, NULL, &amp;error)) {
    /* there was an error */
    return;
}
mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_NONE);
table_name = gda_value_new (G_TYPE_STRING);
g_value_set_string (value, "customers");
dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_TABLE,
                                  NULL, NULL, 
                                  table_name, &amp;error);
gda_value_free (table_name);
if (dbo) {
    /* the "customers" table has been found, its details are in dbo */
    GdaMetaTable *table = GDA_META_TABLE (dbo);
    GSList *list;
    for (list = table-&gt;columns: list; list = list-&gt;next) 
        g_print ("Column: %s\n", ((GdaMetaTableColumn*) list-&gt;data)-&gt;column_name);
}
else
    g_print ("Table not found\n");
g_object_unref (mstruct);
      </pre>
<p>
    </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.32</div>
</body>
</html>